﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.announcers.announcerinteractions {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Classes.announcers.*;
    import Classes.announcers.ui.*;

    public class AnnouncerInteractionSpeechBubble extends BaseAnnouncerInteraction implements IAnnouncerInteraction {

        private var m_currBubble:AnnouncerSpeechBubble;
        private var m_bubbleText:String;
        private var m_offset:Point;

        public function AnnouncerInteractionSpeechBubble(_arg1:AnnouncerData, _arg2:XML){
            super(_arg1);
            this.m_bubbleText = _arg2.attribute("text").toString();
            this.m_offset = new Point();
            if (_arg2.attribute("offsetX").length() > 0){
                this.m_offset.x = parseInt(_arg2.attribute("offsetX").toString());
            };
            if (_arg2.attribute("offsetY").length() > 0){
                this.m_offset.y = parseInt(_arg2.attribute("offsetY").toString());
            };
        }
        private function createBubble():void{
            this.destroyBubble();
            this.m_currBubble = new AnnouncerSpeechBubble();
            this.m_currBubble.setMessage(ZLoc.t("Announcers", this.m_bubbleText));
            this.m_currBubble.x = this.m_offset.x;
            this.m_currBubble.y = this.m_offset.y;
            (m_announcerData.npc.displayObject as Sprite).addChild(this.m_currBubble);
            Global.stage.addEventListener(MouseEvent.CLICK, this.onStageClick, false, 0, true);
        }
        private function destroyBubble():void{
            if (this.m_currBubble){
                if (this.m_currBubble.parent){
                    this.m_currBubble.parent.removeChild(this.m_currBubble);
                };
                this.m_currBubble = null;
                Global.stage.removeEventListener(MouseEvent.CLICK, this.onStageClick);
            };
        }
        public function activate():void{
            if (this.m_currBubble){
                this.destroyBubble();
            } else {
                this.createBubble();
            };
        }
        private function onStageClick(_arg1:MouseEvent):void{
            if (((!(m_announcerData.npc)) || (!(m_announcerData.npc.isHighlighted())))){
                this.destroyBubble();
            };
        }

    }
}//package Classes.announcers.announcerinteractions 
